
using System;
using WebLog;
internal sealed class DatabaseInfo
{

    public static int COUNTRY_EDITION = 1;
    public static int REGION_EDITION_REV0 = 7;
    public static int REGION_EDITION_REV1 = 3;
    public static int CITY_EDITION_REV0 = 6;
    public static int CITY_EDITION_REV1 = 2;
    public static int ORG_EDITION = 5;
    public static int ISP_EDITION = 4;
    public static int PROXY_EDITION = 8;
    public static int ASNUM_EDITION = 9;
    public static int NETSPEED_EDITION = 10;


    private string info;


    public DatabaseInfo(string info)
    {
        this.info = info;
    }

    public int getType()
    {
        if ((info == null) | (info == ""))
        {
            return COUNTRY_EDITION;
        }
        else
        {

            return Convert.ToInt32(info.Substring(4, 7)) - 105;
        }
    }


    public bool isPremium()
    {
        return info.IndexOf("FREE") < 0;
    }


    public DateTime getDate()
    {
        for (int i = 0; i < info.Length - 9; i++)
        {
            if (Char.IsWhiteSpace(info[i]) == true)
            {
                string datestring = info.Substring(i + 1, i + 9);
                try
                {

                    return DateTime.ParseExact(datestring, "yyyyMMdd", null);

                }
                catch (Exception e)
                {
                    Logger logger = Logger.GetInstance;
                    logger.WriteLog(e);
                }
                break;
            }
        }
        return DateTime.Now;
    }

    public string tostring()
    {
        return info;
    }
}


